package org.yenn.pattern.aliyun.behavioral.strategy;

import org.junit.Test;
import org.yenn.pattern.aliyun.behavioral.strategy.impl.OperationAdd;
import org.yenn.pattern.aliyun.behavioral.strategy.impl.OperationMultiply;
import org.yenn.pattern.aliyun.behavioral.strategy.impl.OperationSubstract;

import static org.junit.Assert.*;

/**
 * 步骤 4
 * 使用 Context 来查看当它改变策略 Strategy 时的行为变化。
 */
public class StrategyPatternDemo {
    /**
     * 步骤 5
     * 验证输出。
     *
     * 10 + 5 = 15
     * 10 - 5 = 5
     * 10 * 5 = 50
     */
    @Test
    public void executeStrategy() {
        Context context = new Context(new OperationAdd());
        System.out.println("10 + 5 = " + context.executeStrategy(10, 5));

        context = new Context(new OperationSubstract());
        System.out.println("10 - 5 = " + context.executeStrategy(10, 5));

        context = new Context(new OperationMultiply());
        System.out.println("10 * 5 = " + context.executeStrategy(10, 5));
    }
}